// pages/my/qrcode/setmoney.js
const App = getApp()

Page({
  data: {

    cash: 0,//零钱余额
    show: !0,
    form: {
      money: '',
    },
  },



  onLoad(options) {
    this.WxValidate = App.WxValidate({
      money: {
        required: true,
        minlength: 1,
        maxlength: 10,
        number: true,
      },
    }, {
        money: {
          required: '请输入金额',
        },
      })



    console.log(">>>>>>>>>>>>>>>>>>>>>")
    console.log(options)
    console.log(options.cash)


    this.setData({
      cash: options.cash
    })




    //this.address = App.HttpResource('/address/:id', { id: '@id' })
  },


  submitForm(e) {
    const params = e.detail.value
    const money = params.money


    console.log(e.detail.value)
    console.log(e.detail.value.cash)



    if (!this.WxValidate.checkForm(e)) {
      const error = this.WxValidate.errorList[0]
      App.WxService.showModal({
        title: '友情提示',
        content: `${error.msg}`,
        showCancel: !1,
      })
      return false
    }


    if (parseFloat(money) > parseFloat(this.data.cash)) {

      App.WxService.showModal({
        title: '友情提示',
        content: '付款金额超过您的余额，请重新输入!',
        showCancel: !1,
      })
      return false

    } else if (params.money <= 0) {
      App.WxService.showModal({
        title: '友情提示',
        content: `请输入正确金额`,
        showCancel: !1,
      })
      return false
    }
     else {
      console.log(e)
      App.WxService.navigateTo('/pages/my/qrcode/newcode?money=' + money)
    }



  },

  showToast(message) {
    App.WxService.showToast({
      title: message,
      icon: 'success',
      duration: 1500,
    })
      .then(() => App.WxService.navigateBack())
  },




  toIndex(e) {
    console.log(e)
    //App.WxService.navigateTo('/pages/index/index')
    wx.switchTab({
      url: '/pages/index/index'
    })
  }


})